package com.xzw.servlet;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.CircleCaptcha;
import cn.hutool.captcha.GifCaptcha;
import cn.hutool.captcha.LineCaptcha;

import javax.jws.WebService;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.URLPermission;

@WebServlet(urlPatterns = "/xzwCode")
public class CodeServlet extends HelloWorldServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取 session
        HttpSession session = req.getSession();
        GifCaptcha gifCaptcha = CaptchaUtil.createGifCaptcha(60, 20, 4);
        //获取验证码的值
        String code = gifCaptcha.getCode();
        //将获取的验证码储存到session中，
        session.setAttribute("CCC",code);

        gifCaptcha.write(resp.getOutputStream());
    }
}
